<template>
  <div>
    <form action>
      <label>
        姓名:
        <input type="text" name="name" v-model="name" class="name" id />
      </label>
      <br />
      <label>
        年龄:
        <input type="number" name="age" v-model="age" id />
      </label>
      <br />
      <label>
        身高:
        <input type="number" name="height" v-model="height" id />
        （米）
      </label>
      <br />
      <label>
        体重:
        <input type="number" name="weight" v-model="weight" id />
        (公斤)
      </label>
      <br />
      <label>
        病史:
        <input type="text" v-model="disease" id />
      </label>
      <br />
      <button type="button" @click="getResult">诊断</button>
    </form>
    <div>{{ result }}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      age: "",
      height: "",
      weight: "",
      disease: "",
      result: ""
    };
  },
  methods: {
    getResult() {
      this.BMI = this.weight / (this.height * this.height);
      if (this.BMI <= 18.5) {
        this.result = "患者" + this.name + "的诊断结果：" + "过轻";
      } else if (this.BMI > 18.5 && this.BMI <= 24.9) {
        this.result = "患者" + this.name + "的诊断结果：" + "正常";
      } else if (this.BMI > 24.9 && this.BMI <= 29.9) {
        this.result = "患者" + this.name + "的诊断结果：" + "过重";
      } else if (this.BMI > 29.9) {
        this.result = "患者" + this.name + "的诊断结果：" + "肥胖";
      }
      this.name = "";
      this.age = "";
      this.height = "";
      this.weight = "";
      this.disease = "";
    }
  }
};
</script>

<style>
</style>